package com.sx.pipeline.custom.dialog;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.lxj.xpopup.core.BottomPopupView;
import com.lxj.xpopupext.listener.CommonPickerListener;
import com.sx.mvvmlibs.base.EasyAdapter;
import com.sx.pipeline.R;
import com.sx.pipeline.adapter.ChooseBankCardAdapter;
import com.sx.pipeline.arouth.RoutePath;

import java.util.ArrayList;
import java.util.List;

/**
 * author : zhouyouqiang
 * e-mail : 1638473898@qq.com
 * date   : 2022/4/12 13:57
 * desc   :
 * version: 1.0
 */
public class DialogChooseBankCard extends BottomPopupView {

    private RecyclerView recyclerView;
    private TextView tvAddBank;
    private ChooseBankCardAdapter adapter;
    private List<String> datas=new ArrayList<>();

    public DialogChooseBankCard(@NonNull Context context, List<String> list) {
        super(context);
        this.datas = list;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_choose_bank_card;
    }

    ImageView ivClose;

    @Override
    protected void onCreate() {
        super.onCreate();
        ivClose = findViewById(R.id.iv_close);
        tvAddBank = findViewById(R.id.tv_add_bank);
        recyclerView = findViewById(R.id.recyclerView);
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        tvAddBank.setOnClickListener(v -> {
            ARouter.getInstance().build(RoutePath.Wallet.BANK_CARD).navigation();
            dismiss();
        });
        initRv(datas);
    }

    private void initRv(List<String> list) {
        adapter = new ChooseBankCardAdapter(getContext(), list);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
        recyclerView.setAdapter(adapter);
        adapter.setSelectMode(EasyAdapter.SelectMode.SINGLE_SELECT);
        adapter.setOnItemSingleSelectListener(new EasyAdapter.OnItemSingleSelectListener() {
            @Override
            public void onSelected(int itemPosition, boolean isSelected) {
                if (commonPickerListener != null)
                    commonPickerListener.onItemSelected(itemPosition, list.get(itemPosition));
                dismiss();
            }
        });
    }

    @Override
    protected void applyDarkTheme() {
        super.applyDarkTheme();
//        btnCancel.setTextColor(Color.parseColor("#999999"));
//        btnConfirm.setTextColor(Color.parseColor("#ffffff"));
//        getPopupImplView().setBackground(XPopupUtils.createDrawable(getResources().getColor(R.color._xpopup_dark_color),
//                popupInfo.borderRadius, popupInfo.borderRadius, 0, 0));
    }

    @Override
    protected void applyLightTheme() {
        super.applyLightTheme();
//        btnCancel.setTextColor(Color.parseColor("#666666"));
//        btnConfirm.setTextColor(Color.parseColor("#222222"));
//        getPopupImplView().setBackground(XPopupUtils.createDrawable(getResources().getColor(R.color._xpopup_light_color),
//                popupInfo.borderRadius, popupInfo.borderRadius, 0, 0));
    }

    private CommonPickerListener commonPickerListener;

    public DialogChooseBankCard setCommonPickerListener(CommonPickerListener commonPickerListener) {
        this.commonPickerListener = commonPickerListener;
        return this;
    }
}

